package parDef

import (
	"context"
	"database/sql"
	"db2s/global"
	"db2s/outPut"
	"time"
)

const (
	Single = "single"
)

type (
	NewExecSqlS struct {
		DB      *sql.DB
		Options Options
	}
	SqlFilter struct {
		WhereSql string
		WhereAdd string
	}
	Encryption struct {
		Schema     string
		LockFunc   string
		UnlockFunc string
		Column     []string
	}
	Object struct {
		LogSeq            string
		Schema            string
		RecoverSchema     string
		RecoverTable      string
		LockCol           Encryption
		Table             string
		Partition         string
		Index             IndexColumnMe
		Column            []ColMetaMapS
		IndexCol          []string
		TruncatePartition []string
		LobLogo           bool
	}
	AlterDDLOptions struct {
		Rule string
	}
	Options struct {
		Expect              string
		Scn                 string
		StopTime            time.Duration
		WhereSql            string
		WhereAdd            []map[string]string
		SqlMode             bool
		TablePx             string
		FixRows             int64
		AlterDDL            AlterDDLOptions
		LowerCaseTableNames bool
		SqlLogBin           bool //是否忽略binlog
		RowsLimit           int
		SqlFilter           SqlFilter
		RepairMethod        string //应用sql修复方式
	}
	ExecDDL struct {
		Sql       string                `json:"sqlText"`
		FilePoint outPut.FileOperations `json:"-"`
	}
	ExecDML struct {
		Sql       string                `json:"sqlText"`
		FilePoint outPut.FileOperations `json:"-"`
	}
	InsertSql struct {
		Prefix   string
		QueryCol []ColMetaMapS
		Columns  []ColMetaMapS
		Values   []string
	}
	Parameter struct {
		Con          *sql.DB `json:"-"`
		Meta         any
		Object       Object    `json:"object"`
		Options      Options   `json:"options"`
		ExecInsert   InsertSql `json:"insert"`
		ExecDDL      ExecDDL   `json:"execDDL"`
		ExecDML      ExecDML   `json:"execDML"`
		ExecFunc     func(s any, execFunc any) (any, error)
		GetJsonValue func(s any, key string) (any, error)
		ExecSqlFunc  func(ctx context.Context, S any, GisValFunc func(any) any, sessionOptions, sqlStr []string, expect string) (global.Return, error)
	}
	ColumnMe struct {
		Parameter Parameter `json:"parameter"`
	}
)
type (
	ColTypeValueMap struct {
		ColTypeMap string `json:"colTypeMap"`
		ShowValue  int64  `json:"showValue"`
		ShowString string `json:"showString"`
		MinValue   int64  `json:"minValue"`
		MaxValue   int64  `json:"maxValue"`
		Precision  int64  `json:"precision"`
		Scale      int64  `json:"scale"`
		UseByte    int64  `json:"useByte"`
		Variable   bool   `json:"variable"` //是否变长，true为变长，false为不变长
		Symbol     bool   `json:"symbol"`   //表示是有符号还是无符号的,可选值：true 表示无符号，false表示有符号
		Zerofill   bool   `json:"zerofill"` //表示显示是否补充0，int(11) --> 数据为 9 显示为-> 00000000009
	}
	ColMetaMapS struct {
		DatabaseName     string          `json:"databaseName"`
		TableName        string          `json:"tableName"`
		ColumnName       string          `json:"colName"`
		ColumnSeq        string          `json:"colSeq"`
		TypeBelong       string          `json:"typeBelong"` //所属类型 属于时间、还是数值还是字符串等
		Type             ColTypeValueMap `json:"type"`
		ColNullMap       string          `json:"colNullMap"`
		Charset          string          `json:"charset"`
		CollationName    string          `json:"collationName"`
		ColDefaultMap    string          `json:"colDefaultMap"`
		BeforeColName    string          `json:"beforeColName"`
		ColAutoIncrement bool            `json:"colAutoIncrement"`
		Invisible        bool            `json:"invisible"`
		ColumnComment    string          `json:"colComment"`
		Virtual          VirtualColumn   `json:"virtual"`
		OnUpdate         OnUpdate        `json:"onUpdate"`
	}
)
